<?php

namespace App\Http\Controllers\User;

use App\Http\Controllers\BaseController;
use App\Models\UserStorePlan;
use App\Rules\Code;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class StorePlanController extends BaseController
{
    public function index()
    {
        $count = UserStorePlan::query()->count('id');
        return $this->success($count);
    }

    public function store(Request $request)
    {
        $param = $this->validate($request,[
            'firm_profession_id' => 'required|integer',
            'exp_type' => 'required|in:1,2',
            'is_store' => 'required|in:1,2',
            'plan_time' => 'required|date_format:Y-m',
            'city' => 'required',
            'phone' => 'required',
            'budget_amount' => 'required',
            'code' => ['required',new Code()]
        ]);

        $param['user_id'] = auth('api')->id();
        $plan =  UserStorePlan::query()->create($param);

        if ($plan->getKey()){
            return $this->success();
        }

        return  $this->error();

    }
}
